package io.sodabox.web.utils;

import io.sodabox.web.oauth.utils.AccessGrant;

import java.util.Map;

import org.vertx.java.core.json.JsonObject;

public class JsonUtil {

	public static JsonObject getJsonObject(AccessGrant accessGrant) {

		JsonObject json = new JsonObject();
		json.putString("key", accessGrant.getKey());
		json.putString("secret", accessGrant.getSecret());
		json.putString("providerId", accessGrant.getProviderId());

		Map<String, Object> attributes = accessGrant.getAttributes();
		if(attributes != null){
			JsonObject jsonAttr = new JsonObject();
			for (String key : attributes.keySet()) {
				jsonAttr.putString(key, attributes.get(key).toString());
			}
			json.putObject("attributes", jsonAttr);
		}
		return json;

	}

}
